import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
//import java.awt.Cursor;
import java.awt.Frame;
//import java.awt.GridBagConstraints;
//import java.awt.GridBagLayout;
import java.awt.GridLayout;
//import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;




public class BlackBoard extends Frame{

	public static void main (String[] args){
		new BlackBoard();

	}
	
	BlackBoard(){
		super("Menu:");
		mb = new MyMenuBar();
		this.setMenuBar(mb);
		this.setLayout(new GridLayout(1,2));
		//this.setLayout(layout);
		this.setSize(200,150);
		this.setLocation(150, 200);
		this.setResizable(false);

		/*
		 * Left
		 */
		Panel menuP = new Panel();
		colors = new ColorPanel();
		menuP.setLayout(new GridLayout(4,2));
		
		Button clear = new Button("Clear");
		Button undo =  new Button ("Undo");
		Choice stCh = new Choice();
			stCh.addItem("1");
			stCh.addItem("2");
			stCh.addItem("4");
			stCh.addItem("8");
			stCh.addItem("12");
			stCh.addItem("16");
			stCh.addItem("20");
			stCh.addItem("24");
		stCh.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent arg0) {
				stroke = Integer.parseInt(arg0.getItem().toString());
			}	
		});
		clear.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				board.clear();
			}		
		});
		undo.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				board.undo();
			}		
		});
		
		menuP.add(undo);
		menuP.add(clear);
		menuP.add(new Label("stroke width:"));
		menuP.add(stCh);
		/* 
		 * 
		 * Right Panel
		 * 
		 * */
		/*
		 * 
		 * Main Add
		 * 
		 */
		
		this.add(menuP);
		this.add(colors);
		this.setVisible(true);
	
		/*
		 * 
		 * 	Canvas Listener 
		 * 
		 * 
		 */
		board.setBackground(Color.white);
		new Board(board, mb);
		
		board.addMouseListener(new MouseAdapter() {

			public void mousePressed(MouseEvent arg0) {
				board.myNewLine(arg0.getPoint(), colors.getColor(),stroke);
			}
		});
		board.addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseDragged(MouseEvent arg0) {
				board.addPoint(arg0.getPoint());
			}
		});
		
		/*
		 * Menu Listener
		 */
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent arg0) {
				System.exit(0);
			}
		});
		
		
	}
	private MenuBar mb;
	private ColorPanel colors;
	private int stroke = 1;
	private LineDrawing board = new LineDrawing();
	//private GridBagLayout layout = new GridBagLayout();
	//private GridBagConstraints constrains = new GridBagConstraints(0,0,0,0,0,0,0,GridBagConstraints.RELATIVE ,new Insets(10,0,0,0), 2,2);
	private static final long serialVersionUID = -6062451137973029481L;
	
	class MyMenuBar extends MenuBar{
		
		MyMenuBar(){
			super();
			MenuItem export = new MenuItem("Export", new MenuShortcut(KeyEvent.VK_E));
			MenuItem save = new MenuItem("Save", new MenuShortcut(KeyEvent.VK_S));
			MenuItem open = new MenuItem("Save", new MenuShortcut(KeyEvent.VK_O));
			MenuItem exit = new MenuItem("Exit", new MenuShortcut(KeyEvent.VK_Q));
			MenuItem help = new MenuItem("Help", new MenuShortcut(KeyEvent.VK_P));
			save.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {		
				}
			});	
			open.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {		
				}
			});
			exit.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {		
					System.exit(0);
				}
			});
			export.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {

				}
			});
			help.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					new Help();
				}
			});	
			//datei.add(export);
			datei.add(help);
			datei.add(exit);
			this.add(datei);
			
		}
		Menu datei = new Menu("Datei");
		
		private static final long serialVersionUID = 1L;
	}
}
